<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>队伍考核-关联单位</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <style>


        .clearfix:after {
            content: '';
            display: block;
            clear: both;
        }

        .button {
            border: 1px solid #589df5;
            height: 30px;
            line-height: 30px;
            min-width: 80px;
            cursor: pointer;
            box-shadow: 0px 0px 2px 2px #0b6e94;
            background-color: none;
            background: transparent;
            color: #ffffff;
        }

        #left-div {
            width: 80px;
            float: left;
        }

        #left-div1 {
            width: 100%;
        }

        #left-div2 {
            width: 100%;
            /*height: 250px;*/
            overflow: hidden;
        }

        #left-table2 {
            margin-bottom: 4px;
        }

        #right-div {
            float: left;
            /*width: 240px;*/
        }

        #right-div1 {
            width: 100%;
            overflow: hidden;
        }

        #right-div2 {
            width: 100%;
            /*height: 250px;*/
            overflow: auto;
        }

        #right-table1 {
            /*width: 320px;*/
        }

        #right-table2 {
            /*width: 320px;*/
            overflow: auto;
        }

        th, td {
            height: 50px;
            width: 80px;
            line-height: 50px;
            overflow: hidden;
            text-align: center;
        }

        #right-table2 > tbody > tr > td {
            width: 70px;
            height: 69px;
        }

        #left-div1::-webkit-scrollbar {
            display: none
        }

        .customtable tbody tr td {
            padding: 0px;
        }
        .layui-input{
            border:0px;
        }
    </style>
</head>
<body>
<form class="layui-form" id="formedit" name="formedit" action="create_kpiscore" method="post"
      target="d41d8cd98f00b204e9800998ecf8427e">
    <iframe name="d41d8cd98f00b204e9800998ecf8427e" src="about:blank" style="display:none;"></iframe>
    <div class="indexcontent clearfix" style=" overflow: hidden">


        <div id="left-div" style="width: 20%;height: 100%">
            <div id="left-div1" style="width: 100%;height: 100%;overflow: scroll">

                <table class="layui-table" style="margin-top: 0px">

                    <tbody>
                    <tr>
                        <td colspan="2" style="height: 120px">被评单位</td>
                    </tr>

                    <tr>
                        <td colspan="2">全局</td>
                    </tr>

                    <c:forEach var="item" items="${databody}" varStatus="idxStatus1">
                        <tr>
                            <c:if test="${item['rowspan']!=0 && item['rowspan']!=null}">
                                <td rowspan="${item['rowspan']}" style="vertical-align: middle"
                                    valign="middle">${item['groupname']}</td>
                            </c:if>

                            <c:if test="${item['rowspan']==0&&item['groupid']==null}">
                                <td style="vertical-align: middle"
                                    valign="middle"></td>
                            </c:if>
                            <td>
                                <div style="width: 130px">${item['orgname']}</div>
                            </td>

                        </tr>
                    </c:forEach>

                    </tbody>
                </table>
            </div>

            <div class="left-div2">
                <table class="layui-table" id="left-table2">


                </table>


            </div>
        </div>

        <div id="right-div" style="width: 80%;height: 100%">
            <div id="right-div1">


                <div class="selftable" id="selftable">
                    <table cellspacing="0" cellpadding="0" border="0" class="layui-table customtable"
                           style="margin:0; " id="test">

                        <tr>


                            <c:forEach var="cmap" items="${columt}" varStatus="idxStatus">
                                <td colspan="${cmap.value}">

                                    <div style="width: 70px;  word-wrap: break-word;
word-break: normal;  ">${cmap.text}</div>
                                </td>

                            </c:forEach>
                            <td rowspan="2"><div style="width: 70px">总计</div></td>
                            <td class="orderScore" rowspan="3">
                                <div style="width: 70px">排名</div>
                            </td>
                        </tr>

                        <tr>
                            <c:forEach var="itemth" items="${titleh}" varStatus="idxStatus">
                                <td style="text-align: center">
                                    <div style="width: 70px;height: 86px;line-height: 86px;">${itemth.uassingredients }</div>

                                </td>
                            </c:forEach>
                        </tr>



                    </table>


                </div>
            </div>
            <div id="right-div2" style="width: 100%;height: 285px">

                <table id="right-table2" cellspacing="0" cellpadding="0" border="0" class="layui-table customtable"
                       style="margin:0; ">

                    <tbody>
                    <tr>
                        <c:forEach var="itemth" items="${titleh}" varStatus="idxStatus">
                            <td align="center" style="text-align: center">

                                <c:if test="${read == 1}">
                                    <div style="width: 70px; height: 67px;line-height: 67px">
                                <span class=" sum_${itemth.assindexid} sum_${idxStatus.index+1}  sum "

                                      name="sum_${itemth.assindexid}"
                                      style="width: 70px"


                                >${itemth.sumscore}</span></div>
                                </c:if>
                                <c:if test="${read == 0}">


                                    <input type="text" valign="middle"
                                           class="layui-input sum_${itemth.assindexid}"
                                           style="width: 70px;display: inline;height: 67px;line-height: 67px"
                                           name="sum_${itemth.assindexid}"
                                           value="${itemth.sumscore}"
                                    >
                                </c:if>
                                    <%--<span class="sum_${idxStatus.index+1}  sum" ></span>--%>

                            </td>

                        </c:forEach>
                        <td class="allNum">

                            <div style="width: 70px"><fmt:formatNumber type="number" value="${sumscore}"
                                                                       pattern="#.000"/></div>
                        </td>
                    </tr>

                    <c:forEach var="item" items="${databody}" varStatus="idxStatus1">
                        <tr class="orginfo orginfo_${idxStatus1.index+1}">

                            <c:forEach var="itembody" items="${titleh}" varStatus="idxStatus">
                                <td>

                                    <div style="width: 70px">
                                        <c:if test="${read == 1}">
                                            <c:if test="${itembody.datatype==2}">
                                    <span
                                            class="  score num_${idxStatus.index+1}"
                                            data-index="${idxStatus.index}"

                                    >${item[itembody.assindexidcolum]}</span>
                                            </c:if>
                                            <c:if test="${itembody.datatype==1}">
                                    <span
                                            class="  num_${idxStatus.index+1}"
                                            data-index="${idxStatus.index}"
                                            style="width: 70px"


                                    >${item[itembody.assindexidcolum]}</span>
                                            </c:if>
                                        </c:if>
                                        <c:if test="${read == 0}">


                                            <c:if test="${itembody.datatype==2}">

                                                <input type="text" name="score_${item['orgid']}_${itembody.assindexid}"
                                                       autocomplete="off"
                                                       class="layui-input  score  num_${idxStatus.index+1}"
                                                       data-index="${idxStatus.index}"
                                                       style="width: 70px"
                                                       value="${item[itembody.assindexidcolum]}">
                                            </c:if>
                                            <c:if test="${itembody.datatype==1}">


                                                <input type="text" name="score_${item['orgid']}_${itembody.assindexid}"
                                                       autocomplete="off"
                                                       class="layui-input    num_${idxStatus.index+1}"
                                                       data-index="${idxStatus.index}"

                                                       value="${item[itembody.assindexidcolum]}">
                                                <input name="score_${item['orgid']}_${itembody.assindexid}"
                                                       type="hidden"
                                                       value="0">
                                            </c:if>


                                        </c:if></div>

                                </td>

                            </c:forEach>
                            <td class="weight_sum_${idxStatus1.index+1}    group "
                                groupId="${item['groupid']==null?item['orgid']:item['groupid']}">
                                 <div style="width: 70px"></div>

                            </td>
                            <td class="orderScore">
                                <div style="width: 55px"></div>
                            </td>

                        </tr>
                    </c:forEach>

                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div style="margin:0 auto;margin-top: 10px;width:90%;color:#ffffff" class="toolbar">
        <table style="width:100%">
            <tr>
                <td style="text-align: center" colspan="2">
                    <button class="button" lay-submit="" lay-filter="demo1" id="btnsave">保存打分</button>


                    <input type="button" value="关闭" class="button" style="margin-top:10px"
                           onclick="top.CloseOpenWindow()"/>
                </td>
                <td>
                    <input type="hidden" value="${templateid}" name="templateid">
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" id="hidRead" value="${read}">
</form>


<script>
    function CloseDialog(result, msg) {
        top.frames["iframe"].vWorkTemplate.addresult(result, msg);
    }

    $(function () {

        $('.indexcontent').css('height', $(window).height() + "px");

        var height = $(window).height() - $('#right-div1').height();
        $('#right-div2').css('height', height + "px")

        $('#right-div2').on('scroll', function () {
            var top = $(this).scrollTop();
            var left = $(this).scrollLeft();
            $('#left-div1').scrollTop(top);
            $('#right-div1').scrollLeft(left);
        })

        $('#left-div1').on('scroll', function () {
            var top = $(this).scrollTop();
            var left = $(this).scrollLeft();
            $('#right-div2').scrollTop(top);
            // $('#right-div1').scrollLeft(left);
        })



        Array.prototype.unique3 = function () {
            var res = [];
            var json = {};
            for (var i = 0; i < this.length; i++) {
                if (!json[this[i]]) {
                    res.push(this[i]);
                    json[this[i]] = 1;
                }
            }
            return res;
        }

        function sequence(a, b) {
            return b - a;
        }

        var read = $('#hidRead').val();
        if (read == 1) {
            $(":input").attr("disabled", "disabled");
            $('.toolbar').hide();
            $('.orderScore').show();
            // $('#right-div').css('margin-left', '144px')

        } else {
            $('.orderScore').hide();

        }
        var length = $('.sum').length;
        var allNum = 0;
        for (var i = 1; i < length + 1; i++) {
            var rows = $('.num_' + i);
            var num = 0;
            for (var j = 0; j < rows.length; j++) {
                var node = $(rows[j]);


                if (read == 1) {
                    if (node.text() != null && node.text() != "") {
                        num += parseFloat(node.text());
                    }

                } else {
                    if (node.val() != null && node.val() != "") {
                        num += parseFloat(node.val());
                    }
                }


            }
            //  $('.sum_' + i).text(num.toFixed(3))
            allNum += num;


        }

        //   $('.allNum').text(allNum.toFixed(3));

        for (var i = 1; i < length + 1; i++) {

            var rows = $('.num_' + i);
            for (var j = 0; j < rows.length; j++) {
                var node = $(rows[j]);
                var weight = $('.weightTitle_' + i).val() || $('.weightTitle_' + i).text();
                var rs = "";

                if (read == 1) {
                    rs = parseFloat($(node[0]).text());

                } else {
                    rs = parseFloat($(node[0]).val());

                }
                // if (!isNaN(rs))
                //     $($(node[0]).parent().next().children()[0]).text(rs)

            }

        }

        var weightRow = $('.orginfo').length;
        for (var i = 1; i < weightRow + 1; i++) {

            var row = $('.orginfo_' + i);
            var weights = row.find('.score');
            var weightNum = 0;
            for (var j = 0; j < weights.length; j++) {

                var node = 0;
                if (read == 1) {
                    node = $($($(weights[j]))[0]).text()


                } else {
                    node = $($($(weights[j]))[0]).val()
                }

                weightNum += parseFloat(checkText(node))
            }

            if (!isNaN(weightNum))
                $($('.weight_sum_' + i).children()[0]).html(weightNum.toFixed(3))

        }

        var sumScore = $('.group');

        var groupIds = [];
        for (var i = 0; i < sumScore.length; i++) {

            groupIds.push($($(sumScore[i])[0]).attr('groupid'));

        }
        groupIds = groupIds.unique3();

        for (var i = 0; i < groupIds.length; i++) {

            var groupScores = [];
            for (var j = 0; j < sumScore.length; j++) {

                if ($(sumScore[j]).attr('groupid') == groupIds[i]) {
//同一分组的分数
                    groupScores.push($(sumScore[j]).text());
                }

            }


            groupScores = groupScores.unique3().sort(sequence);
            var index = 0;
            for (var l = 0; l < groupScores.length; l++) {

                index++;
                {
                    for (var k = 0; k < sumScore.length; k++) {
                        if ($(sumScore[k]).attr('groupid') == groupIds[i])
                            if (groupScores[l] == $(sumScore[k]).text()) {


                                $($($($($(sumScore[k]))[0]).next()[0]).children()[0]).html(index)
                            }
                    }
                }


            }

        }


    })

    function checkText(text) {
        if (text == '' || text == null || text == undefined)

            return 0
        else
            return text;

    }

    function doExport() {
        var str = document.getElementById("test").outerHTML;
        document.all.excelText.value = str;
        $('#form1').submit();
    }


</script>


</body>
</html>